package com.hand.wyc24548.infra.repository.impl;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.hzero.export.vo.ExportParam;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.springframework.stereotype.Component;

import com.hand.wyc24548.domain.entity.SoHeader;
import com.hand.wyc24548.domain.repository.SoHeaderRepository;
import com.hand.wyc24548.infra.mapper.SoHeaderMapper;

import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;

/**
 * @Author wangyc
 * @create 2019/8/8 10:48
 */

@Component
public class SoHeaderRepositoryImpl extends BaseRepositoryImpl<SoHeader> implements SoHeaderRepository {

    private final SoHeaderMapper soHeaderMapper;

    public SoHeaderRepositoryImpl(SoHeaderMapper soHeaderMapper) {
        this.soHeaderMapper = soHeaderMapper;
    }

    @Override
    public Page<SoHeader> selectSoHeader(SoHeader soHeader, PageRequest pageRequest) {
        return PageHelper.doPage(pageRequest,() -> soHeaderMapper.selectSoHeader(soHeader));
    }

    /**
     * 根据订单id查询
     * @param soHeaderId
     * @return
     */
    @Override
    public SoHeader selectOrderId(Long soHeaderId) {
        SoHeader soHeader=new SoHeader();
        soHeader.setSoHeaderId(soHeaderId);
        List<SoHeader> soHeaders=soHeaderMapper.selectSoHeader(soHeader);
        return CollectionUtils.isNotEmpty(soHeaders) ? soHeaders.get(0):null;
    }

    @Override
    public SoHeader insertSoHeader(SoHeader soHeader) {
        return soHeaderMapper.insertSoHeader(soHeader);
    }

    @Override
    public List<SoHeader> export(SoHeader soHeader, ExportParam exportParam, PageRequest pageRequest) {
        return null;
    }

}
